package xyz.jangle.action;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import xyz.jangle.model.BsAttachment;
import xyz.jangle.service.BsAttachmentService;

@Controller
@RequestMapping("/bsAttachmentCtrl")
public class BsAttachmentCtrl {

	@Autowired
	private BsAttachmentService bsAttachmentService;
	
	protected Logger logger = Logger.getLogger(getClass());

	@RequestMapping("/insert.ctrl")
	@ResponseBody
	public Map<String, Object> insert(BsAttachment record) {
		return bsAttachmentService.insertOrUpdate(record);
	}

	@RequestMapping("/deleteByPrimaryKey.ctrl")
	@ResponseBody
	public Map<String, Object> deleteByPrimaryKey(BsAttachment record) {
		return bsAttachmentService.deleteByPrimaryKey(record);
	}

	@RequestMapping("/selectPage.ctrl")
	@ResponseBody
	public Map<String, Object> selectPage(BsAttachment record) {
		return bsAttachmentService.selectPage(record);
	}

	@RequestMapping("/selectByPrimaryKey.ctrl")
	@ResponseBody
	public Map<String, Object> selectByPrimaryKey(BsAttachment record) {
		return bsAttachmentService.selectByPrimaryKey(record);
	}

	@RequestMapping("/batchDeleteByPrimaryKey.ctrl")
	@ResponseBody
	public Map<String, Object> batchDeleteByPrimaryKey(BsAttachment record) {
		return bsAttachmentService.batchDeleteByPrimaryKey(record);
	}

	// 附件上传(表单上附件的name属性值应当为file，或者将该参数file改为与表单name属性一致。)
	@RequestMapping(value = "/uploadBatch", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
	public @ResponseBody Map<String, Object> uploadBatch(HttpServletRequest request,
			@RequestParam("file") MultipartFile[] files, BsAttachment record) {
		return bsAttachmentService.uploadBatch(files,record);
	}
	
	@RequestMapping("/downLoadById.ctrl")
	@ResponseBody
	public void downLoadById(BsAttachment record,HttpServletResponse response) {
		bsAttachmentService.downLoadById(record,response);
	}

}
